package com.xh.bussiness.permission.controller;

import com.xh.bussiness.permission.bean.request.RoleMenuRequest;
import com.xh.bussiness.permission.service.IRoleMenuService;
import com.xh.core.bean.AjaxResult;
import com.xh.core.constant.AjaxResultConstant;
import com.xh.core.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = "角色菜单接口")
@RestController
@RequestMapping("/permission/roleMenu")
public class RoleMenuController extends BaseController {

    @Autowired
    private IRoleMenuService roleMenuService;


    @ApiOperation(value = "查询角色菜单",notes = "查询角色菜单")
    @PostMapping("/queryAll")
    public AjaxResult queryAll(RoleMenuRequest bean){
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, "", roleMenuService.queryRoleMenu(bean));
    }


    @ApiOperation(value = "角色菜单新增",notes = "角色菜单新增")
    @PostMapping(value="/add")
    @Transactional
    public AjaxResult add(RoleMenuRequest bean){
        String msg=roleMenuService.addRoleMenu(bean);
        return new AjaxResult(msg==null,msg);
    }


    @ApiOperation(value = "角色菜单修改",notes = "角色菜单新增修改")
    @PostMapping(value="/modify")
    @Transactional
    public AjaxResult modify(RoleMenuRequest bean){
        String msg=roleMenuService.modifyRoleMenu(bean);
        return new AjaxResult(msg==null,msg);
    }


    @ApiOperation(value = "角色菜单删除",notes = "角色菜单删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "角色菜单id",required = true,dataType = "String")
    })
    @PostMapping("/delete")
    @Transactional
    public AjaxResult delete(String id){
        String msg=roleMenuService.deleteRoleMenu(id);
        return new AjaxResult(msg==null,msg);
    }
}

